package java8._06_使用流收集数据;

import com.google.common.collect.Sets;

import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import java.util.function.BiConsumer;
import java.util.function.BinaryOperator;
import java.util.function.Function;
import java.util.function.Supplier;
import java.util.stream.Collector;

public class _03_MyListCollector<T> implements Collector<T, List<T>, List<T>> {

    private Set<Characteristics> sets = Sets.newHashSet(Characteristics.UNORDERED);

    public _03_MyListCollector(Set<Characteristics> sets) {
        if (sets == null) {
            return;
        }
        this.sets = sets;
    }

    @Override
    public Supplier<List<T>> supplier() {
        return ArrayList::new;
    }

    @Override
    public BiConsumer<List<T>, T> accumulator() {
        return (list, item) -> list.add(item);
    }

    @Override
    public BinaryOperator<List<T>> combiner() {
        return (listA, listB) -> {
            listA.addAll(listB);
            return listA;
        };
    }

    @Override
    public Function<List<T>, List<T>> finisher() {
        return item -> {
            System.out.println("finisher-------------------另外で一条，华丽の分割线----------------------");
            return item;
        };
    }

    @Override
    public Set<Characteristics> characteristics() {
        return sets;
    }
}
